package com.coolingme.algo_01_list.copylist;

/**
 * 带有随机指针的链表
 *
 * @author wangyue
 * @date 2020/11/3 14:43
 */
public class LinkedRandomNode {

    /**
     * 值
     */
    public Object value;

    /**
     * 下一个值
     */
    public LinkedRandomNode next;

    /**
     * 随机指针
     */
    public LinkedRandomNode random;

    public LinkedRandomNode(Object value) {
        this.value = value;
    }

    public LinkedRandomNode setNext(Integer value) {
        this.next = new LinkedRandomNode(value);
        return next;
    }

    @Override
    public String toString() {
        String result = this.value.toString();
        if (this.random != null) {
            result += "(" + this.random.value + ")";
        }
        if (this.next != null) {
            result += " => " + this.next.toString();
        }
        return result;
    }
}
